'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async socketfind() {
    const { ctx } = this;
    const { id } = ctx.request.body;
    if (!id) {
      return ctx.body = { success: false, msg: 'id不能为空' };
    }
    try {
      const to = await ctx.model.Socketim.findAll({
        where: {
          to: id,
        },
      });
      const from = await ctx.model.Socketim.findAll({
        where: {
          from: id,
        },
      });
      const msglist = to.concat(from);
      msglist.sort((a, b) => {
        return a.imid - b.imid;
      });
      ctx.body = { success: true, data: msglist };
    } catch (e) {
      ctx.body = { success: false };
    }
  }

}

module.exports = HomeController;
